package com.example.excise06.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class FileUpLoadConfig implements WebMvcConfigurer {
    //注入配置文件中配置的值
    @Value("${application.file.diskpath}")
    private String diskPath;
    @Value("${application.file.fileurl}")
    private String fileUrl;

    //添加虚拟目录配置,将文件夹与访间路由绑定
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler(this.fileUrl+"/**")//访问的路由
                .addResourceLocations("file:"+this.diskPath);//对应的文件夹
    }
}